package com.cskaoyan.opensource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * 创建日期: 2022/11/18 15:03
 *
 * @author ciggar
 */
public class C3p0Utils {

    static DataSource dataSource;

    static {
        // 构建C3p0的数据库连接池
        dataSource = new ComboPooledDataSource();

    }


    // 获取连接
    public static Connection getConnection(){
        Connection connection = null;
        try {
            connection = dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }

    public static DataSource getDataSource() {
        return dataSource;
    }
}
